"""
4. 写一个Python脚本实现找到/tmp目录及其子目录下的以.htm结尾的文件，把其后缀名改为.html
"""

import os
from pathlib import Path


def get_drives():
    drives = []
    for partition in psutil.disk_partitions():
            drives.append(partition.device)
    return drives

if(os.name == 'nt'):
    import psutil
    drives = get_drives()
    for dk in drives:
        for fd in os.walk(Path(dk)):
            p = Path(fd[0])
            if p.stem == 'tmp':
                for f in fd[2]:
                    f_ = Path(f)
                    if f_.suffix == '.htm':
                        src_name = str(fd[0]) + '\\' + str(f_)
                        new_file_name = f_.stem + '.html'
                        dst_name = str(fd[0]) + '\\' + str(new_file_name)
                        os.rename(src_name, dst_name)
elif(os.name == 'posix'):
    for fd in os.walk('/'):
            p = Path(fd[0])
            if p.stem == 'tmp':
                for f in fd[2]:
                    f_ = Path(f)
                    if f_.suffix == '.htm':
                        src_name = str(fd[0]) + '/' + str(f_)
                        new_file_name = f_.stem + '.html'
                        dst_name = str(fd[0]) + '/' + str(new_file_name)
                        os.rename(src_name, dst_name)
    
print("over")